#ifndef __TOKEN_PARSER__
#define __TOKEN_PARSER__
#include <string>
#include <vector>
#include <map>
#include "luastyle.h"
#include "Token.h"
#include <QString>
#include <QHash>
#include <QVector>
using namespace std;

#define IS_WORD_SYMBOL(ch) ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_' || ch == '.')
#define IS_WHITESPACE(ch) (ch == ' ' || ch == '\t')

class TokenParser
{
    QVector<LuaToken *> m_tokens;
	int m_position;    
    QHash<QString, TokenTypeEnum> m_keywords;
    bool m_skipNewLines;
    bool m_skipComments;
public:
    ~TokenParser();
    TokenParser();
	void parseData(const char * aData);
	bool isCommentStart(const char * aData, int aOffset, int aLength, int & aCommentLength, int & aIndent);
    //bool isLongBracketEnd(const char * aData, int aOffset, int aDataLength, int & aLength, int & aIndent);
	bool isLongBracketStart(const char * aData, int aOffset, int aDataLength, int & aLength, int & aIndent);
	LuaToken * goToStart();
	LuaToken * goToEnd();
	LuaToken * next();
	LuaToken * previous();
	LuaToken * current();
	void mergeSimilarTokens(vector<LuaToken *> & aMerged);
    void setTypeForRange(TokenTypeEnum aType, LuaToken * aStart, LuaToken * aEnd);
    LuaToken * findTokenOfType(TokenTypeEnum aType, int aIndent);
    bool goToToken(LuaToken *aToken);
    QVector<LuaToken *> &getTokens();
    bool needSuggestions(int aOffset);
    QString getModifiedWord(int aOffset, int aCharacter);
    void setSkipNewLines(bool aSkip);
    void setSkipComments(bool aSkip);
    bool getWordBoundaries(int aOffset, int & aStart, int & aLength);
    LuaToken * getTokenByOffset(int aOffset);
    //merge word token and dots between them
    void mergeWords();
    LuaToken *findLongBracketEnd(int aIndent);
    void fillCommentsAndStrings();
    int getClosingLongBracketLength(int aIndex);
};
#endif
